package net.wanho.servlet;

import com.alibaba.fastjson.JSON;
import net.wanho.util.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Author：汤小洋
 * Date：2024-07-29 15:53
 * Description：<描述>
 */
@WebServlet("/regist")
public class RegistServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        int age = Integer.parseInt(req.getParameter("age"));
        double height = Double.parseDouble(req.getParameter("height"));
        System.out.println(username + ":" + password + ":" + age + ":" + height);

        resp.setHeader("Access-Control-Allow-Origin", "*"); // 允许跨域访问
        resp.setContentType("application/json;charset=utf8");
        PrintWriter out = resp.getWriter();

        AjaxResult result = new AjaxResult();
        result.setStatus(200);
        result.setMsg("注册成功");

        out.print(JSON.toJSONString(result));
        out.close();
    }
}
